package com.ruoyi.orderdetails.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.orderdetails.domain.Orderdetails;
import com.ruoyi.orderdetails.service.IOrderdetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单细节Controller
 * 
 * @author sqlstudent
 * @date 2025-06-13
 */
@RestController
@RequestMapping("/orderdetails/orderdetails")
public class OrderdetailsController extends BaseController
{
    @Autowired
    private IOrderdetailsService orderdetailsService;

    /**
     * 查询订单细节列表
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(Orderdetails orderdetails)
    {
        startPage();
        List<Orderdetails> list = orderdetailsService.selectOrderdetailsList(orderdetails);
        return getDataTable(list);
    }

    /**
     * 导出订单细节列表
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "订单细节", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Orderdetails orderdetails)
    {
        List<Orderdetails> list = orderdetailsService.selectOrderdetailsList(orderdetails);
        ExcelUtil<Orderdetails> util = new ExcelUtil<Orderdetails>(Orderdetails.class);
        util.exportExcel(response, list, "订单细节数据");
    }

    /**
     * 获取订单细节详细信息
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @GetMapping(value = "/{orderDetailId}")
    public AjaxResult getInfo(@PathVariable("orderDetailId") Long orderDetailId)
    {
        return success(orderdetailsService.selectOrderdetailsByOrderDetailId(orderDetailId));
    }

    /**
     * 新增订单细节
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "订单细节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orderdetails orderdetails)
    {
        return toAjax(orderdetailsService.insertOrderdetails(orderdetails));
    }

    /**
     * 修改订单细节
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "订单细节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orderdetails orderdetails)
    {
        return toAjax(orderdetailsService.updateOrderdetails(orderdetails));
    }

    /**
     * 删除订单细节
     */
    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @Log(title = "订单细节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailIds)
    {
        return toAjax(orderdetailsService.deleteOrderdetailsByOrderDetailIds(orderDetailIds));
    }
}
